package com.jindy.module.versionmanagement.controller;

import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.page.TableDataInfo;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.versionmanagement.domain.VersionManagement;
import com.jindy.module.versionmanagement.service.VersionManagementService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 版本管理Controller
 *
 * @author zhaoxi
 * @date 2022-12-16
 */

@Api(tags = "业务后台 - 版本管理 ")
@RestController
@RequestMapping("/module/version")
@Validated
@Slf4j
public class VersionManagementController extends BaseController {

    @Resource
    private VersionManagementService versionManagementService;


    /**
     * 查询版本数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(VersionManagement version){
        startPage();
        List<VersionManagement> list = versionManagementService.selectVersionList(version);
        return getDataTable(list);
    }

    /**
     * 根据id查询版本信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult get(@PathVariable("id") String id) {
        return AjaxResult.success(versionManagementService.selectVersionById(id));
    }

    /**
     * 新增版本数据
     */
    @Log(title = "新增版本", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody VersionManagement version)
    {
        return toAjax(versionManagementService.insertVersion(version));
    }

    /**
     * 修改版本数据
     */
    @Log(title = "修改版本", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody VersionManagement version) {
        return toAjax(versionManagementService.updateVersion(version));
    }

    /**
     * 删除版本
     */
    @Log(title = "删除版本", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(versionManagementService.deleteVersionById(id));
    }

    /**
     * 批量删除
     */
    @Log(title = "批量删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult removes(@PathVariable String[] ids)
    {
        return toAjax(versionManagementService.deleteVersionByIds(ids));
    }
}
